package com.happe.foodeasy.manage.controller.commodity;

import com.happe.foodeasy.manage.commodity.entity.CommodityTypeEntity;
import com.happe.foodeasy.manage.helper.RetrieveDataHelper;
import com.happe.foodeasy.manage.service.CommodityTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * This class is used to skip another page.
 * Created by wubin on 2016-07-10.
 */
@Controller
@RequestMapping("/skipView")
public class SkipViewController {
    private Logger logger = LoggerFactory.getLogger(SkipViewController.class);

    @Resource
    private CommodityTypeService commodityTypeService;
    @Resource
    private RetrieveDataHelper retrieveDataHelper;

    @RequestMapping("/index.do")
    public String skipIndexManage() {
        logger.info("in skipIndexManage method");
        CommodityTypeEntity firstTypeEntity = commodityTypeService.selectFirstValidType();
        return "redirect:/commodity/retrieveTargetCommodities.do?commodityStatusId=0&commodityTypeId=" + firstTypeEntity.getId();
    }

    @RequestMapping("/addCommodity.do")
    public ModelAndView skipAddCommodity() {
        ModelAndView modelAndView = new ModelAndView("commodity/addCommodityBaseInfo");
        retrieveDataHelper.addAllCommodityTypeInMAV(modelAndView).addAllProvinceInMAV(modelAndView);
        return modelAndView;
    }
}